<!doctype html>
<html lang="en">
	<head>
		<meta charset="UTF-8">
		<meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">
		<title></title>
		<script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
		<script src="https://res.wx.qq.com/open/js/jweixin-1.0.0.js" type="text/javascript" charset="utf-8"></script>
	</head>
	<style type="text/css">
		*{
			-webkit-touch-callout:none;
			-webkit-user-select:none;
			-khtml-user-select:none;
			-moz-user-select:none;
			-ms-user-select:none;
			user-select:none;
			-o-user-select:none;
		}
	</style>
	<body>
	</body>
	<script type="text/javascript">
 		function add(m) { return m < 10 ? '0' + m : m }
		function timeToDate(data) {
			var d = new Date(data);//ʱ����ǵó���1000�ٽ��д���
			var year = d.getFullYear();
			var month = d.getMonth() + 1;
			var date = d.getDate();
			var hour = d.getHours();
			var minute = d.getMinutes();
			var second = d.getSeconds();
			// return year + "-" + month + "-" + date + " " + hour + ":" + minute + ":" + second;
			return year + "-" + add(month) + "-" + add(date) + " " + add(hour) + ":" + add(minute) + ":" + add(second);
		}

		function getQueryString(name) {
			var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
			var r = window.location.search.substr(1).match(reg);
			if(r != null) return unescape(r[2]);
			return null;
		}
		console.log(getQueryString('code'))
		console.log(getQueryString('deviceId'))
		console.log(getQueryString('state'))

		$.ajax({
			type:"post",
			url:"http://39.104.99.181:8711/weChat/message/openid",
			// url:"http://192.168.2.195:8711/weChat/message/openid",
			async:true,
			data:{
				code: getQueryString('code')
			},
			success:function(message){
				console.log(message)
				if(message.code == 5000){
					localStorage.setItem('openId', message.data.openId)
					sessionStorage.setItem('nickname', message.data.nickName)
					sessionStorage.setItem('country', message.data.country)
					// sessionStorage.setItem('sex', message.sex)
					sessionStorage.setItem('headimgurl', message.data.headImgUrl)											
					if (getQueryString('state') != 123) {
						location.href = 'index.html?_' + new Date().getTime() + '#/login?&deviceId=' + getQueryString('state');
					} else {
						location.href = 'index.html?_' + new Date().getTime();
					}					
				}
				else if(message.code==200){
					localStorage.setItem('openId', message.data.openId)
					sessionStorage.setItem('nickname', message.data.nickName)
					sessionStorage.setItem('country', message.data.country)
					// sessionStorage.setItem('sex', message.sex)
					sessionStorage.setItem('headimgurl', message.data.headImgUrl)
					if (getQueryString('state') != 123) {
						location.href = 'index.html?_' + new Date().getTime() + '#/addDevice?&deviceId=' + getQueryString('state');
					}else{
						location.href = 'index.html?_' + new Date().getTime() + '#/deviceList'
					}					
				} 			
 			}
		})		
	</script>

</html>